<?php
	$workers = []; //进程池
	$worker_num = 3; //创建进程数量

	//创建 启动进程
	for ($i = 0; $i < $worker_num; $i++) {
		$process = new swoole_process('doProcess'); //创建单独新进程
		$pid = $process->start(); //启动进程，并获取ID
		$workers[$pid] = $process; //存入进程池
	}

	//创建进程执行函数
	function doProcess(swoole_process $process) {
		$process->write("PID:$process->pid"); //子进程写入信息
		echo "写入信息：$process->pid $process->callback \n";
	}

	//添加进程事件 向每一个子进程添加需要执行的操作
	foreach ($workers as $worker) {
		//添加
		swoole_event_add($worker->pipe, function($pipe) use ($worker) {
			$data = $worker->read(); //读取数据
			echo "接受到：$data \n";
		});
	}
